export default function expandArray(data, level = 1) {
  let tempArr = []
  Array.from(data).forEach(item => {
    if (item.children) {
      const expanded = item._expanded === undefined ? false : item._expanded
      this.$set(item, '_expanded', expanded)
    }

    item._level = level
    tempArr.push(item)
    if (item._expanded) {
      const children = expandArray.call(this, item.children, item._level + 1)
      tempArr = tempArr.concat(children)
    }
  })
  return tempArr
}
